<?php

namespace App\Http\Controllers;

use Alipay\OpenAPISDK\Util\AlipaySignature;
use Illuminate\Http\Request;

class NotifyController extends Controller
{

    private $appid = '2021004170645344';
    protected $privateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCwA6+7LuBROUMF1MK10mrv8H1xK/9zB6PUjF+3mvaTCE4+OLZSIU72UuGoXkeZIQE9VEwqPFqTAsvWBuBOGim26frlBJxh0zUX+hwyFGxPiM55jvI+YCWo3wEfOT9QUk8Lw3U0H8C/VLl6xd7hbLb0ajbjDfPQEP86yCigngZfI+E0WpOGiVcl1Qp+vXqzWJi0iGFI2W7dBLbik+mRE1wKOjwU3KD1EdyWbLz8Eu69q4/5ReiYKi+nZTPWRSdxqwdsY1EoJECaj2M38O7iaKGhpf9SkeT7A+6n61C8DfBOZSV2ipkVp6azAAu6+SkJIFsDxuRzi1YZ3HZpq7nVlhdBAgMBAAECggEALfaoez8AgPVtFSa8OfLazhGFEHqm2IkUNTr6+91Rqo+urvzsT4I3NofqOad1Fv3RbwyGXzknheBjDl75UCvw3L05MXkExV78LGi52DIRHqvhD0lO5Q8ChpjFmDvA1t7HmZDPGG96S/x5+x+U1lUnaaga8SwBkUH/BICka10Y2Nr8yDAjfkItRiw0PPcBRwOOKkNXLtDXrqVFjMgb0vpna3DovyVkfW4FaADoA4M63KpPvxF+BfYDrN9BmiKoBrIjWrVCAArgG/2W8lBoAZKuP0IdG6YFfXLE475hltDmPDk31rXkVm3SXSqSiOAIzx8QROHMgFU+aHcYIN/VuvucaQKBgQDeA8nwVOz7iHnnfqsT9MUjVel9fMuWE7p+54doMg0VtlSOQccXUBSttYGkL/xKktaQid5JOu5qIN7K/f23qbVWWnhtsrvU2imQqMkz7qZaNKmOU2POMT7TEGFijvJ2ck6o9w4cCnMLCxgo3scs3ow6oE8crRkJjuhlFMORlOjLHwKBgQDK9UFzrfsVCQFZfdq43cwDkWWyXy+GpExXAPo/NVjAAKnAnJK+8b+Z84Wl4TD2cNH/+6MkHT2KyPyayRPMJQd2Lj1jmo0/GjaRyk+TMVkImdOKEiFqxe/LWMilfWW236f4zecggW9pvU/409cDFvwgkaD8P2ejL9Vk1J+KIQExnwKBgQCXA3i+suWnioNxBWYU4u+dQ3jY1KQeZzj5zT77jt/7ntQRF4j2wI/wQH/4UHOJviuYkU7T/PPi2IzzAqUr4pHoNQ2pgGPnOqX/Me/6FSCuRxf2KZ6/yBt1sbSsN5ORIduDbtj4Fdt+7YL3eeF9EbvMvPJTDSL0r3JAH0mPovxd/QKBgHXmaUJBBEWg+Ja7JK8VsWk1MoWfA+XMVciI+dZ0L/1BpVsN2bVwjCRrsey914qh2WxCCvB0yAZyYUOtoYGK1T3S+Lh+1KSenqqsgvN3zEfRzHA9vgnfuEBBcDWqlcbZQCOpwSVB663aWrWqohHabVaiIonGb3b915H+bjt4ls/zAoGBAJe7WuYw30MTMOmzyiJN8Q9dgW8S/8JqD30qkkkm61b3wfZITrgYYlJIO6pVe5mhIzRYzY7wCjiNQu+ouMNmhkX7yfkkjpXod+cSWpUSNZ1rSAx2xOJT9swy1J9lzDqnpDKqz0Z00rPN7Isg2NJbortcnxHjc3DYsuLk77Nlkns9';
    protected $publicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhpPDIA+tt/P1YCuXc4QPNSqfF1XYYuj3He45vm8hrxBqJaLJos+UWRhWJjvF3hT/F3X9sUhppexjlArFYRiJ06UTdiPMU66tj6I8GXIH7udgkVix2upoVRODFnGeTsvKb6K28wErBrWv2nTZ2a8FGbC7cgD89VmHjSl/6WM8gA3OihLjxl0jFME9RQJ016/DSA+S0GIjbC/KdIzi1yHAvWAt56+gPROLi/YQxXqXafwFf96e/w99w6rrkE/Osiw3NHxImTa1lLLg+GQr2oLKhw08USKdMdJLqxvJzDZ8KPwtv4ayn5IjQ1+7AWvzHMegz2oiSr0WYy9Q4KLxMC+KHQIDAQAB';

    public function pay(Request $request)
    {
        $params = $request->all();
        file_put_contents('pay.json', json_encode($params, JSON_UNESCAPED_UNICODE));
//        $dir = 'storage/pay_notify/' . date('Ymd');
//        if (!is_dir($dir)) {
//            mkdir($dir, 0777, true);
//        }
//
//        file_put_contents($dir . '/notify_req.json', json_encode($params, JSON_UNESCAPED_UNICODE));
//        if (AlipaySignature::rsaCheckV1($params, $this->publicKey)) {
//            file_put_contents($dir . '/notify_success.json', json_encode($params, JSON_UNESCAPED_UNICODE));
//        } else {
//            file_put_contents($dir . '/notify_error.json', json_encode($params, JSON_UNESCAPED_UNICODE));
//        }
        echo "success";
    }
}
